package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.TObstacle;
import com.ruoyi.common.core.domain.entity.TReceiveStation;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IObstacleDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.List;

/**
 * @Auther: Stanley.Y
 * @Date: 2024/6/18 15:05
 * @Description: 障碍物数据管理Controller类
 * @Version 1.0.0
 */

@RestController
@Anonymous
@RequestMapping("/system/obstacle")
public class ObstacleDataController extends BaseController {

    @Autowired
    private IObstacleDataService obstacleDataService;

    /**
     * 获取所有障碍物数据
     * @return
     */
    @GetMapping("/getObstacleDataList")
    public AjaxResult getObstacleDataList(){
        return success(obstacleDataService.getObstacleDataList());
    }

    /**
     * 获取障碍物数据列表
     */
    @PreAuthorize("@ss.hasPermi('basedata:obstacle:list')")
    @GetMapping("/list")
    public TableDataInfo list(TObstacle obstacle) {
        startPage();
        List<TObstacle> list = obstacleDataService.selectObstacleDataList(obstacle);
        return getDataTable(list);
    }

    /**
     * 根据障碍物主键ID获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('basedata:obstacle:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable String id) {
        TObstacle result = obstacleDataService.selectObstacleDataById(id);
        return success(result);
    }

    /**
     * 新增障碍物数据
     */
    @PreAuthorize("@ss.hasPermi('basedata:obstacle:add')")
    @Log(title = "障碍物数据维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TObstacle obstacle) {
        obstacle.setCreateTime(new Timestamp(System.currentTimeMillis()));
        return toAjax(obstacleDataService.insertObstacleData(obstacle));
    }

    /**
     * 修改障碍物数据
     */
    @PreAuthorize("@ss.hasPermi('basedata:obstacle:edit')")
    @Log(title = "障碍物数据维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TObstacle obstacle)
    {
        return toAjax(obstacleDataService.updateObstacleData(obstacle));
    }

    /**
     * 删除障碍物数据
     */
    @PreAuthorize("@ss.hasPermi('basedata:obstacle:remove')")
    @Log(title = "障碍物数据维护", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(obstacleDataService.deleteObstacleDataByIds(ids));
    }
}
